#!/bin/bash
set -e

handle_error() {
    echo "错误发生在 $1 行，命令为 $2"
    exit 1
}

trap 'handle_error $LINENO "$BASH_COMMAND"' ERR

export HOMEDIR=$(dirname $(readlink -f "${BASH_SOURCE[0]}"))
source $HOMEDIR/scripts/init-env.sh

source $HOMEDIR/scripts/install-ptk-checkos.sh

echo 请确认检查无异常，输入 y 或 Y,回车继续安装，否则退出
p=""
read p
if [ "$p" == "Y" ] || [ "$p" == "y" ]; then
    echo "继续安装"
else
    echo "用户操作退出"
    exit 1
fi

source $HOMEDIR/scripts/install-mogdb.sh
source $HOMEDIR/scripts/set-global-param.sh
source $HOMEDIR/scripts/create-database.sh

echo 实例已安装完成，已成功创建数据库 $ptk_global_biz_dbname
echo 执行 su - $ptk_global_user 切换到数据库安装用户下
echo 执行 gsql -r -d $ptk_global_biz_dbname 连接数据库